import java.util.Stack;

public class Test_Ball {

    public static void main(String[] args) {
        String[] ops = {"5","2","C","D","+"};
        calPoints(ops);
    }

    public static int calPoints(String[] ops) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < ops.length; i++) {
            String str = ops[i];
            if(isNumber(str)){
                int number = Integer.parseInt(str);
                stack.push(number);
            }else{
                switch (str){
                    case "C":
                        stack.pop();
                        break;
                    case "D":
                        stack.push(2 * stack.peek());
                        break;
                    case "+":
                        int num = stack.pop();
                        int num2 = stack.peek();
                        stack.push(num);
                        stack.push(num + num2);
                }
            }
        }
        int ret = 0;
        while (!stack.isEmpty()){
            ret += stack.pop();
        }
        return ret;
    }
    public static boolean isNumber(String str){
        if (str.equals("C") || str.equals("D") || str.equals("+")){
            return false;
        }
        return true;
    }
}
